package com.shwread.android.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.ImageView;
import com.shwread.android.qysw10000204.R;

public class LoadingDialog
        extends
        Dialog
{
	private ImageView         img;
	private Context           context;
	private AnimationDrawable drawable;
	
	public LoadingDialog(Context context) {
		super(context, R.style.loading_dialog);
		this.context = context;
		findViews();
		setCanceledOnTouchOutside(true);
		getWindow().setLayout(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		getWindow().setGravity(Gravity.CENTER);
		WindowManager.LayoutParams winlp = getWindow().getAttributes();  
		winlp.alpha = 0.8f; // 0.0-1.0  
		getWindow().setAttributes(winlp); 
	}
	
	private void findViews() {
		View view = LayoutInflater.from(context).inflate(R.layout.loading_dialog, null);
		img = (ImageView) view.findViewById(R.id.loading_dialog_img);
		setContentView(view);
		
		
		
	}
	
	@Override
	public void show() {
	    super.show();
	    drawable = (AnimationDrawable) img.getDrawable(); // .getBackground();
		drawable.start();
	}

	@Override
    public void dismiss() {
	    super.dismiss();
	    if(drawable!=null && drawable.isRunning()){
	    	drawable.stop();
	    	drawable = null;
	    }
    }
	
	
}
